import numpy as np
import sys


def binary_championship_selection(tmp_pop):
    """
    二元锦标赛排序
    :param tmp_pop:按照快速非支配排序排好的中间种群
    :return:被选中的种群
    """
    size = len(tmp_pop)
    # print("====================================")
    # print("size:",size)
    pop = []
    count = 0
    for i in range(0, size):
        first = np.random.randint(0, size)
        sec = np.random.randint(0, size)
        chosen = first if first <= sec else sec
        # print("chosen==========================", end="")
        # print(tmp_pop[chosen].duration)
        pop.append(tmp_pop[chosen])
        count += 1
        if count == size / 2:
            break
    # print(len(pop))
    # sys.exit(666)
    return pop
